const app=new Vue({
    el:'#app',
    data:{
        books:[
            {id:1,name:"java",data:"2024",price:50.2,count:1},
            {id:2,name:"C",data:"2024",price:50.2,count:21},
            {id:3,name:"Go",data:"2024",price:50.2,count:41},
            {id:4,name:"Python",data:"2024",price:50.2,count:51}
        ]
    },
    methods:{
        decrement(index){
            this.books[index].count++
        },
        increment(index){
            this.books[index].count--
        },
        removeHandle(index){
                this.books.splice(index,1)
        }
    },
    computed:{
        totalPrice(){
            // let totalPrice=0
            // for(let i=0;i<this.books.length;i++){
            //         totalPrice+=this.books[i].price*this.books[i].count
            // }
            // for(let i in this.books){

            // }
            //第三种方式:
            let totalPrice=0
            for(let item of this.books){
                totalPrice+=item.price*item.count
            }
            
            return  totalPrice
        }
    },
    filters:{
        showPrice(price){
            return '￥'+price.toFixed(2)
        }
    }
})

const nums=[23,34,54,3,2,23,4,343,54,34]

let newNums =nums.filter(function(n){
    return n>50
})
let newNums2=newNums.map(function(n){
    return n*2
})
 newNums2=newNums2.reduce(function(var1,var2){
    return var1+var2
},0)

let total=nums.filter(function(n){
    return n<50
}).map(function(n){
    return n*2
}).reduce(function(pre,n){
    return pre+n
},0)
console.log(total)
